package daoimpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import dao.PartOfListDAO;
import database.MySQLConnector;
import dto.PartOfListDTO;
import exceptions.DALException;

public class PartOfListDAOImpl implements PartOfListDAO {

	public MySQLConnector conn = null;
	

	public PartOfListDAOImpl() throws DALException {
		conn = new MySQLConnector();
	}
	
	@Override
	public List<PartOfListDTO> getPartOfList (int userId) throws DALException {
		List<PartOfListDTO> list = new ArrayList<PartOfListDTO>();
		ResultSet rs = conn.doQuery("call GetPart(" + userId + ")");
		try {
			while (rs.next()) {
				list.add(new PartOfListDTO(rs.getString(1), rs.getInt(2)));
			}
		} catch (SQLException e) {
			throw new DALException(e);
		}
		return list;
	}
	
	@Override
	public void closeConnection () throws DALException {
		this.conn.closeConnection();
	}

}
